package com.example.chat.controller;
import com.example.chat.domain.dto.PageQueryDTO;
import com.example.chat.result.Result;
import com.example.chat.service.ChatService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/chats")
@CrossOrigin
@Tag(name = "私聊相关接口")
public class ChatController {

    @Resource
    private ChatService chatService;

    @Operation(summary = "查询用户私聊对话列表")
    @GetMapping("/list")
    public Result getChatList(){
        return chatService.getChatList();
    }

    @Operation(summary = "根据id清空私聊未读消息")
    @PostMapping("/clear/{type}/{id}")
    public Result tipClearOrReduce(@PathVariable Long id,@PathVariable Integer type){
        return chatService.tipClearOrReduce(id,type);
    }

    @Operation(summary = "滚动查询私聊对话消息")
    @PostMapping("/content")
    public Result queryContent(@RequestBody PageQueryDTO chatContentDTO){
        return chatService.queryContent(chatContentDTO.getId()
                ,chatContentDTO.getTimestamp(),chatContentDTO.getOffset());
    }

    @Operation(summary = "根据id删除私聊对话列表")
    @DeleteMapping("/list/{id}")
    public Result deleteChatListById(@PathVariable Long id){
        return chatService.deleteChatListById(id);
    }
}
